import { defineStore } from 'pinia'
import { ref } from 'vue'
import { type UserInfo } from '../Types/userType'
export const useUserStore = defineStore(
  'user',
  () => {
    // state
    const userInfo = ref<UserInfo>({ username: '', token: '' })
    // actions
    // saveUserInfo
    const saveUserInfo = (data: UserInfo) => {
      userInfo.value = Object.assign(userInfo.value, data) //  { userInfo.valueEquals, ...data }
    }
    return { userInfo, saveUserInfo }
  },
  {
    persist: true,
  },
)
